<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // let obj = {
        //     name: '张三',
        //     hobby: ['篮球', '唱歌', '演戏'],
        //     obj1: {
        //         myname: '李四',
        //         age: 60
        //     }
        // }
        // let {name, hobby, obj1} = obj;
        // let [a, b, c] = hobby;
        // let {myname, age} =obj1;
        // console.log(name, hobby , obj1);
        // console.log(a, b, c);

        // let {name, hobby:[a,b,c],obj1:{myname, age}} = obj
        // console.log(name, a, myname);



        // 字符串的解构
        // let str = 'jkjhjhjhkjl';
        // let [a, b, c, d] = str;
        // // let {a, b, c, d} = str; // 不行
        // console.log(a, b, c, d);

        // 包装对象 
        // 基本数据类型有包装对象：number string boolean
        // // undefined null 没有包装对象
        // let str = 'hjhskjdhlkjalk哈哈哈';
        // function render(str,val) {
        //     let str1 = new String(str);
        //     console.log(str1);
        //     return str1.split(val);
        // }
        // var res = render(str, '');
        // console.log(res);

        function fn([a,b,c="默认值"]){
            console.log(a,b,c);
        }
        fn(["张三","李四","王五"]);

        function fun({name = '王源', age}) {
            console.log(name,age);
        }
        fun({age: 18})//王源 18
        // 对象解构时，解构的变量名必须和对象的变量名一致。否则解构出来为undefined
        let {myname , myage} = {hename: '周杰伦', age: 18};
        console.log(myname, myage);//undefined undefined

        let [a,b,c] = ['name', 'age'];
        console.log(a, b, c);

        let [a1, ...rest] = 'hjhkljkjk';
        console.log(a1,rest);// h  ['j', 'h', 'k', 'l', 'j', 'k', 'j', 'k']

        let [head, ...tail] = [1, 2, 3, 4]
        console.log(head, tail) // 1, [2, 3, 4]

        // let [b1, ...rest1] = rest;
        // console.log(b1, rest1);
        // console.log(rest1.join(''));

    </script>
</body>
</html>